实操第一节课(配置 OpenCV 环境并调用)#

课程简介#

时间轴:

  • 00:00 - 07:00 软件包、WSL 2、示例代码概述

  • 07:00 - 16:00 VS Code 界面及插件,文件夹和工作区,生成任务和调试任务

  • 16:00 - 24:00 clang++ 命令行参数:指定寻找头文件路径 (本部分前面绕了弯路)

  • 24:00 - 35:30 从软件包到 pkg-config :库文件包(lib*)和开发文件包(lib*-dev)的一些区别 (偷懒我就直接用 pkg-config 的输出了)

  • 35:30 - 37:30 为什么要学 CMake :谈了下 ROS 1/2 的代码编译工具流软件

  • 37:30 - 49:00 CMakeLists

  • 49:00 - 53:30 cmake-tools extension

  • 53:30 - 59:00 debug !!

  • 59:00 - 62:00 贤者时间

  • 62:00 - 70:30 配置并使用 VcXsrv :(对于 Win10 )宿主机需要下载、安装、运行,子系统需要改环境变量。

  • 后面在解决没解决的问题,然后吹水()

课程大纲#

安装的程序#

你要安装 VS Code 。这节课均以 Ubuntu 20.04 环境为例,为此你要安装以下软件包:(-y表示默认同意依赖包的安装)

sudo apt install build-essential gdb clang++ lldb cmake -y # build-essential depends on g++ and make
sudo apt install python3-opencv libopencv-dev -y

使用 vscode-cpptools 插件包,实现代码提示、跳转,任务生成(代码编译)#

使用 vscode-cmake-tools 插件包,实现基于 CMakeFiles 的代码编译#

学习 CMakeLists 语法#

解决 WSL 2 的一些问题#

VcXsrv#

usbip#

这个还没调通。

出现的指令,补充的指令#

  • 软件包管理器

    使用到的指令有

    apt search <name>
    apt-cahce policy <exact name>
    dpkg -l
    dpkg -L <pkg-name>
    
  • 编译器的帮助文档

    $ clang++ --help
    ...
      -I <dir>                Add directory to the end of the list of include search paths
      -L <dir>                Add directory to library search path
    
    ## [Linker flags](https://clang.llvm.org/docs/ClangCommandLineReference.html#id38)
    Flags that are passed on to the linker
    
    <code>
    -L<dir>, --library-directory <arg>, --library-directory=<arg>
    </code>
    _Add directory to library search path._
    
    <code>
    -Wl,<arg>,<arg2>...
    </code>
    _Pass the comma separated arguments in <arg> to the linker._
    
    <code>
    -l<arg>
    --ld-path=<arg>
    -nostartfiles
    -nostdlib, --no-standard-libraries
    --offload-link
    </code>
    _Use the new offloading linker to perform the link job._
    

    进阶扩展:静态链接和动态链接。(编译原理:编译前端(语法树)、编译后端(优化二进制代码)、链接。)

课程笔记#

  • 学会基本的 Shell 命令行指令,了解使用 Tab 快速补全。(请见缺失的一课)

    扩展:试说明,帮助文档中出现的[ ] < >分别代表什么含义?-V --version等又有什么意义?

    $ vim --help
    
    Usage: vim [arguments] [file ..]       edit specified file(s)
       or: vim [arguments] -               read text from stdin
       or: vim [arguments] -t tag          edit file where tag is defined
       or: vim [arguments] -q [errorfile]  edit file with first error
    
    Arguments:
       --			Only file names after this
       -v			Vi mode (like "vi")
       -e			Ex mode (like "ex")
       -V[N][fname]		Be verbose [level N] [log messages to fname]
       -n			No swap file, use memory only
       -r			List swap files and exit
       -r (with file name)	Recover crashed session
       -L			Same as -r
       -T <terminal>	Set terminal type to <terminal>
       --not-a-term		Skip warning for input/output not being a terminal
       --ttyfail		Exit if input or output is not a terminal
       -u <vimrc>		Use <vimrc> instead of any .vimrc
       -h  or  --help	Print Help (this message) and exit
       --version		Print version information and exit
    
    $ info ls
    
    LS(1)                        General Commands Manual                       LS(1)
    
    NAME
         ls  list directory contents
    
    SYNOPSIS
         ls [-@ABCFGHILOPRSTUWabcdefghiklmnopqrstuvwxy1%,] [--color=when]
            [-D format] [file ...]
    
    ...
    

    扩展:部分语言的 REPL (Read–eval–print loop, also termed an interactive toplevel or language shell) 也可以使用 Tab 补全。你只需要输入一个字母,便可以在 python3 ipython julia 等提供的 REPL 里查看建议。(ipython的使用,请见酒井科协暑培)

    扩展:用过shebang吗?你见过#!/usr/bin/env python3的用法吗?在 Shell 环境中,env FLASK_DEBUG=1 python3 app.py FLASK_DEBUG=1 python3 app.py export FLASK_DEBUG=1; python3 app.py有着基本类似的功能,但是最后一个和前两者不一样哦。

    注意:sudo(superuser do) 是个有趣但危险的指令,使用时你可能将被提示输入密码,这时你的输入不会回显。(什么是回显?请见缺失的一课)

  • WSL 2 使用小技巧

    1. 宿主机(Host, your windows OS)和子系统(Subsystem)的文件如何互相访问?请见 00:04:30 。建议将你的开发文件都存在子系统存储空间内,这应该有篇微软的文章但我懒得找了。

    2. 备用项目

      等待书写

    3. 使用 VcxSrv 要在子系统内显式指定环境变量 DISPLAY 。WSL 2 启动时会创建桥接网络,因此在子系统的解析服务器内可以找到宿主机对应的 IP 。下面这句话将自助的更改当前环境下的 DISPLAY 环境变量。

      export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
      

      你可以将这句话添加到 ~/.bashrc 中(如果你使用的是默认的bash),但加进去之后千万别忘记了啊。

      扩展:你知道类似~/.bashrc的配置文件的加载顺序么?